import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
// import CompressionPlugin from 'compression-webpack-plugin';
import viteCompression from 'vite-plugin-compression'

// https://vite.dev/config/
export default defineConfig({
  base: './',
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  server: {
    // proxy: {
    //   '/api': {
    //     target: 'http://jsonplaceholder.typicode.com',
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, ''),
    //   }
    // }
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) { //这里面的id是每个模块的id
          if (id.includes('node_modules')) { //判断是否是node_modules中的模块
            return 'vendor'; //自定义的名称，这里可以自定义，主要是node-modules中的模块都打包到vendor.js中
          }
        }
      }
    },
    minify: 'terser',
    terserOptions: {
      compress: {
        //生产环境时移出console.log
        drop_console: true,
        drop_debugger: true,
      }
    },
  },
  plugins: [
    vue(),
    viteCompression(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    })

  ],
})
